package test_package;

import java.io.File;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.Scanner;

/**
 * Created by iryna on 3/15/14.
 */
public class fileop {
    private Formatter x;
    private Scanner xy;
    public void openFile(){
        try{
            x = new Formatter("lesson3.txt");
        }
        catch(Exception e){
            System.out.println("you have an error");
        }
    }

    public void addRecords(){
        x.format("%s%n%s%n%s", "gshndgfvhsd 10 sdkhfjsdkf", "hjhhhereeh 1 hhhdhgf", "oiyuuiyhoiuyui 90 kugkjygjkygy");
    }

    public void closeFile(){
        x.close();
    }

    public void deleteFile(){
        try{

            File x = new File("lesson3.txt");

            if(x.delete()){
                System.out.println(x.getName() + " is deleted!");
            }else{
                System.out.println("Delete operation is failed.");
            }

        }catch(Exception e){

            e.printStackTrace();

        }
    }
    public void openFile2(){
        try{
            xy = new Scanner(new File("lesson3.txt"));
        }
        catch(Exception e){
            System.out.println("could not find a file");
        }
    }
    public void readFile(){
        ArrayList<String> list = new ArrayList<String>();

        while (xy.hasNext()){
            list.add(xy.next());
        }


        //System.out.println(list);





    }




}



